import {
  GetDeptListModel,
  BranchListGetResultModel,
  BranchUserListGetResultModel,
  BranchModel,
  RoleModel,
} from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  BranchList = '/branch',
  BranchUserList = '/branch/user',
  Role = '/role',
  User = '/user',
  Security = '/security',
  Code = '/code',
  Config = '/configs',
  Schedule = '/schedule',
  Plugin = '/plugins',
  Log = '/operateLog',
  Message = '/message',
}

export const getPermissionTree = (params) =>
  defHttp.get<any>({ url: `/privilege/id/${params.id}/type/${params.type}/menus`, params });

export const savePermissionTree = (params) =>
  defHttp.put<any>({ url: `/privilege/id/${params.id}/type/${params.type}/menus`, params });

export const getBranchList = (params?: GetDeptListModel) =>
  defHttp.get<BranchListGetResultModel>({ url: Api.BranchList, params });

export const getBranchUserList = (params?: any) =>
  defHttp.get<BranchUserListGetResultModel>({ url: Api.BranchUserList, params });

export const createBranch = (params: BranchModel) =>
  defHttp.post<void>({ url: Api.BranchList, params });

export const editBranch = (params: BranchModel) =>
  defHttp.put<void>({ url: Api.BranchList + `/${params.branchInnercode}`, params });

export const deleteBranch = (ids?: string) =>
  defHttp.delete<void>({ url: Api.BranchList + `/${ids}` });

export const getRoleListByPage = (params) => defHttp.get<any>({ url: Api.Role, params });

export const createRole = (params: RoleModel) => defHttp.post<void>({ url: Api.Role, params });

export const editRole = (params: RoleModel) =>
  defHttp.put<void>({ url: Api.Role + `/${params.roleCode}`, params });

export const deleteRole = (id?: string) => defHttp.delete<void>({ url: Api.Role + `/${id}` });

export const getUserListByPage = (params) => defHttp.get<any>({ url: Api.User, params });

export const getRoleListByBranch = (params?: any) =>
  defHttp.get<any>({ url: Api.User + '/role', params });

export const enableUser = (ids: string) => defHttp.put<void>({ url: Api.User + `/enable/${ids}` });

export const disabledUser = (ids: string) =>
  defHttp.put<void>({ url: Api.User + `/disable/${ids}` });

export const setUserStatus = (ids: string, checked: boolean) => {
  if (checked) {
    return enableUser(ids);
  } else {
    return disabledUser(ids);
  }
};

export const createUser = (params?) => defHttp.post<void>({ url: Api.User, params });

export const updateUser = (params?) =>
  defHttp.put<void>({ url: Api.User + `/${params.userName}`, params });

export const deleteUser = (ids?: string) => defHttp.delete<void>({ url: Api.User + `/${ids}` });

export const initpwdcheck = () => defHttp.get<any>({ url: Api.User + '/initpwdcheck' });

export const updatePassword = (params?) =>
  defHttp.put<void>({ url: Api.User + `/password`, params });

export const changeloginpassword = (params?) =>
  defHttp.put<void>({ url: Api.User + `/changeloginpassword`, params });

export const getSecurity = () => defHttp.get<any>({ url: Api.Security });

export const saveSecurity = (params?) => defHttp.put<void>({ url: Api.Security, params });

export const getCodeList = (params) => defHttp.get<any>({ url: Api.Code, params });

export const getCodeItemList = (codeType: string) =>
  defHttp.get<any>({ url: Api.Code + `/items`, params: { codeType: codeType } });

export const addCodeItem = (params?) => defHttp.post<void>({ url: Api.Code + `/items`, params });

export const updateCodeItem = (params?) => defHttp.put<void>({ url: Api.Code + `/items`, params });

export const delCodeItem = (codeType: string, ids?: string) =>
  defHttp.delete<void>({ url: Api.Code + `/items`, params: { codeType: codeType, items: ids } });

export const addCode = (params?) => defHttp.post<void>({ url: Api.Code, params });

export const updateCode = (params?) => defHttp.put<void>({ url: Api.Code, params });

export const delCode = (ids?: string) =>
  defHttp.delete<void>({ url: Api.Code, params: { codes: ids } });

export const getConfig = () => defHttp.get<any>({ url: Api.Config });

export const saveConfig = (params) => defHttp.put<any>({ url: Api.Config + '/saved', params });

export const getScueduleList = (params) => defHttp.get<any>({ url: Api.Schedule, params });

export const excutedSchedule = (params) =>
  defHttp.post<any>({ url: Api.Schedule + '/executed', params });

export const saveSchedule = (params) => defHttp.put<any>({ url: Api.Schedule, params });

export const getPlugin = (params?) => defHttp.get<any>({ url: Api.Plugin, params });

export const getPluginDetail = (pluginId) =>
  defHttp.get<any>({ url: Api.Plugin + `/service`, params: { pluginId: pluginId } });

export const getUserLoginLog = (params?) =>
  defHttp.get<any>({ url: Api.Log + `/userloginlog`, params });

export const getOperateLog = (params?) =>
  defHttp.get<any>({ url: Api.Log + `/useroperatelog`, params });

export const getSqlLog = (params?) => defHttp.get<any>({ url: Api.Log + `/sqllog`, params });

export const getLogFile = (params?) => defHttp.get<any>({ url: Api.Log + `/logfiles`, params });

export const downloadLogFiles = (params?) =>
  defHttp.get<any>(
    { url: Api.Log + `/download`, params, responseType: 'blob' },
    { isReturnNativeResponse: true },
  );

export const getMessageList = (params) => defHttp.get<any>({ url: Api.Message, params });

export const getMessageDetail = (id) => defHttp.get<any>({ url: Api.Message + `/${id}` });

export const alluserdatabind = (params) =>
  defHttp.get<any>({ url: Api.Message + `/alluserdatabind`, params });

export const selecteduserdatabind = (params) =>
  defHttp.get<any>({ url: Api.Message + `/selecteduserdatabind`, params });

export const addMessageNotice = (params) => defHttp.post<any>({ url: Api.Message, params });

export const setreadflag = (ids) => defHttp.put<any>({ url: Api.Message + `/${ids}/setreadflag` });

export const delMessage = (ids, userType) =>
  defHttp.delete<any>({ url: Api.Message + `/del/${ids}/${userType}` });

export const replyinit = (id) => defHttp.get<any>({ url: Api.Message + `/replyinit/${id}` });

export const replyMessage = (params) => defHttp.post<any>({ url: Api.Message + `/reply`, params });

export const getMessageTypeList = () =>
  defHttp.get<any>({ url: Api.Message + `/getMessageTypeList` });

export const getMessageSubTypeList = () =>
  defHttp.get<any>({ url: Api.Message + `/getMessageSubTypeList` });
